package com.chao.ServerSocket;

import org.junit.Test;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class Server {
    static final int PORT = 1111;

    public static void main(String[] args) throws InterruptedException, IOException {
        ServerSocket server = new ServerSocket(PORT);
        Socket connection = server.accept();
        System.out.println("开启连接："+ connection.getRemoteSocketAddress());
        boolean flag=false;
        Writer out = new OutputStreamWriter(connection.getOutputStream());
        BufferedWriter bw = new BufferedWriter(out);
        while (true) {
            Date now = new Date();
            bw.write(now.toString() );
            bw.newLine();
            bw.flush();
            Thread.sleep(1000);
            if(flag)break;
        }
        connection.close();
        server.close();
    }
}
